home *** CD-ROM | disk | FTP | other *** search
- /*//////////////////////////////////////////////////////////////////////
- Filename: wsn-sdbfncs.js
- Company Name: Computer Associates International, Inc.
- Legal Copyright: Copyright (c) Computer Associates International, Inc.
- Author: Ales Novak
- Product: Tiny Firewall
- Description: javascript code to access active db through XMLSecDBParser COM iface
- ///////////////////////////////////////////////////////////////////////*/
-
- // requires sdb-consts.js + sdb-msgs.js
-
- ///////////////////////////////////////////////////////////////////////
- // getRuleList - internal function
- function getRuleList( bUseClientParser )
- {
- return (parseBoolean(bUseClientParser) != 0) ? external.ClientParser(XM_SBX).RuleList : external.ServerParser(XM_SBX).RuleList;
- }
-
- ///////////////////////////////////////////////////////////////////////
- // getDefinitionList - internal function
- function getDefinitionList( bUseClientParser )
- {
- return (parseBoolean(bUseClientParser) != 0) ? external.ClientParser(XM_SBX).DefinitionList : external.ServerParser(XM_SBX).DefinitionList;
- }
-
- ///////////////////////////////////////////////////////////////////////
- // getExceptionList - internal function
- function getAppExceptionList()
- {
- return external.ServerParser(XM_SBX).AppExceptionList;
- }
-
- function WS_isDefinitionEmpty( strDefID, bUseClientParser)
- {
- var definitionList = getDefinitionList( bUseClientParser );
-
- try
- {
- var oDef = definitionList.Get( strDefID );
-
- var itemEnum = new Enumerator(oDef.ItemList);
- itemEnum.moveFirst();
-
- if ( itemEnum.item() )
- return false;
- }
- catch (e)
- {
- }
-
- return true;
- }
-
-
- ///////////////////////////////////////////////////////////////////////
- // getGlobalOptionsList - internal function
- function getGlobalOptions()
- {
- return external.ServerParser(XM_SBX).GlobalOptions;
- }
-
- function WS_getRule( strRuleID, bUseClientParser)
- {
- try {
- var ruleList = getRuleList( bUseClientParser );
-
- return ruleList.Get(strRuleID);
- }
- catch(e)
- {
- return null;
- }
- }
-
- //////////////// Easy rules support /////////////////////////////
- function WS_easyRulesEnabled( eObjType )
- {
- var eList = new Enumerator( getRuleList( false ) )
- eList.moveFirst();
-
- while (!eList.atEnd())
- {
- var rule = eList.item();
-
- if ( (rule.ObjectType == eObjType) && WS_isEasyRule(rule.Priority==PRIOR_HIGH, rule.Preferred) )
- {
- return rule.Enabled;
- }
-
- eList.moveNext();
- }
-
- return true;
- }
-
- function WS_isEasyRuleByID( strRuleID, bUseClientParser )
- {
- var rule = WS_getRule( strRuleID, bUseClientParser);
-
- if ( rule )
- {
- return WS_isEasyRule(rule.Priority == PRIOR_HIGH, rule.Preferred);
- }
-
- return false;
- }
-
- // nopreferred low priority or preferred high priorit
- function WS_isEasyRule(bHighPriority, bPreferred)
- {
- return ((!bHighPriority && !bPreferred ) || (bHighPriority && bPreferred ));
- }
-
- ///////////////////////////////////////////////////////////////////////
- // WS_SwitchEasyRule
- function WS_SwitchEasyRule( strRuleID )
- {
- try {
-
- var ruleList = getRuleList( false );
-
- var rule = ruleList.Get(strRuleID);
- if (rule)
- {
- var bEasy = WS_isEasyRule(rule.Priority == PRIOR_HIGH, rule.Preferred);
-
- if ( !bEasy )
- {
- rule.Enabled = WS_easyRulesEnabled( rule.ObjectType );
- }
- rule.Preferred = !rule.Preferred;
- }
-
- saveWSChanges(false);
-
- return SUCCESS;
- } catch(e){
- return ErrorHandler( ERR_EDIT_FW_RULE_FAILED, STR_EDIT_FW_RULE_FAILED );
- }
- }
-
-
- ///////////////////////////////////////////////////////////////////////
- // saveWSChanges - internal function
- function saveWSChanges( bUseClientParser, bAvoidSavingSDB )
- {
- if (!bAvoidSavingSDB || !parseBoolean(bAvoidSavingSDB))
- {
- var parser;
- if ( parseBoolean( bUseClientParser ) == 0)
- parser = external.ServerParser(XM_SBX);
- else
- parser = external.ClientParser(XM_SBX);
-
- parser.Save(parser.FilePath);
- }
- }
-
- ///////////////////////////////////////////////////////////////////////
- // WS_AddFileRule
- function WS_AddFileRule( strPathID, strPath, strAppGroupID, strAppLabel, eAppAccountType,
- arRead, alRead, arCreate, alCreate, arWrite, alWrite, arDelete, alDelete,
- strRuleDescription, bHighPriority, bUseClientParser, strUsers, strDayTimeID, strDayTime,
- iOutConditionAND, iOutConditionOR )
- {
- return WS_AddRuleImpl( strPathID, strPath, OT_FILE, false, strAppGroupID, strAppLabel, eAppAccountType,
- AT_FILE_READ, arRead, alRead, AT_FILE_CREATE, arCreate, alCreate, AT_FILE_WRITE, arWrite, alWrite, AT_FILE_DELETE, arDelete, alDelete,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- strRuleDescription, bHighPriority, false, false, bUseClientParser, strUsers, strDayTimeID, strDayTime, iOutConditionAND, iOutConditionOR );
- }
-
- ///////////////////////////////////////////////////////////////////////
- // WS_AddRegistryRule
- function WS_AddRegistryRule( strPathID, strPath, strAppGroupID, strAppLabel, eAppAccountType,
- arRead, alRead, arCreate, alCreate, arWrite, alWrite, arDelete, alDelete,
- strRuleDescription, bHighPriority, bUseClientParser, strUsers, strDayTimeID, strDayTime,
- iOutConditionAND, iOutConditionOR )
- {
- return WS_AddRuleImpl( strPathID, strPath, OT_REGISTRY, false, strAppGroupID, strAppLabel, eAppAccountType,
- AT_KEY_READ, arRead, alRead, AT_KEY_CREATE, arCreate, alCreate, AT_KEY_WRITE, arWrite, alWrite, AT_KEY_DELETE, arDelete, alDelete,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- strRuleDescription, bHighPriority, false, false, bUseClientParser, strUsers, strDayTimeID, strDayTime, iOutConditionAND, iOutConditionOR );
- }
-
- ///////////////////////////////////////////////////////////////////////
- // WS_AddSpawningRule
- function WS_AddSpawningRule( strChildGroupID, strChildLabel, strParentGroupID, strParentLabel, eAppAccountType,
- arSpawn, alSpawn, arChildOwnSecurity, alChildOwnSecurity,
- strRuleDescription, bHighPriority, bUseClientParser, strUsers, strDayTimeID, strDayTime,
- iOutConditionAND, iOutConditionOR )
- {
- return WS_AddRuleImpl( strChildGroupID, strChildLabel, OT_SPAWNING, false, strParentGroupID, strParentLabel, eAppAccountType,
- AT_PROCESS_SPAWN_ENABLED, arSpawn, alSpawn, AT_PROCESS_SPAWN_RUN_UNDER_OWN_SECURITY, arChildOwnSecurity, alChildOwnSecurity, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- strRuleDescription, bHighPriority, false, false, bUseClientParser, strUsers, strDayTimeID, strDayTime, iOutConditionAND, iOutConditionOR );
- }
-
- ///////////////////////////////////////////////////////////////////////
- // WS_AddLoadDllRule
- function WS_AddLoadDllRule( strChildGroupID, strChildLabel, bChildIsDll, strParentGroupID, strParentLabel, eAppAccountType,
- arLoad, alLoad,
- strRuleDescription, bHighPriority, bUseClientParser, strUsers, strDayTimeID, strDayTime,
- iOutConditionAND, iOutConditionOR )
- {
- return WS_AddRuleImpl( strChildGroupID, strChildLabel, OT_SPAWN_DLL, bChildIsDll, strParentGroupID, strParentLabel, eAppAccountType,
- AT_SPAWNDLL_LOAD_DLL, arLoad, alLoad, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- strRuleDescription, bHighPriority, false, false, bUseClientParser, strUsers, strDayTimeID, strDayTime, iOutConditionAND, iOutConditionOR );
- }
-
- ///////////////////////////////////////////////////////////////////////
- // WS_AddDeviceRule
- function WS_AddDeviceRule( strDevice, strAppGroupID, strAppLabel, eAppAccountType,
- arOpen, alOpen, arRead, alRead, arWrite, alWrite, arIoctl, alIoctl, arDangIoctl, arDangIoctl,
- strRuleDescription )
- {
- return WS_AddRuleImpl( "", strPath, OT_DEVICE, false, strAppGroupID, strAppLabel, eAppAccountType,
- AT_DEVICE_OPEN, arOpen, alOpen, AT_DEVICE_READ, arRead, alRead, AT_DEVICE_WRITE, arWrite, alWrite, AT_DEVICE_IOCTL, arIoctl, alIoctl,
- AT_DEVICE_DANGEROUS_IOCTL, arDangIoctl, arDangIoctl,
- 0, 0, 0, 0, 0, 0, 0, 0, 0,
- strRuleDescription );
- }
-
- ///////////////////////////////////////////////////////////////////////
- // WS_AddAccesDescriptorToRuleImpl - do not use it directly from HTML
- function WS_AddAccesDescriptorToRuleImpl( rule, iAccessType, iAccessResult, iAuditLevel )
- {
- var accessDescriptor = rule.AccessDescriptorList.CreateAccessDescriptor();
-
- accessDescriptor.AccessType = parseInt(iAccessType);
- accessDescriptor.AuditLevel = iAuditLevel ? parseInt(iAuditLevel) : 0;
- accessDescriptor.AccessResult = iAccessResult ? parseInt(iAccessResult) : 0;
-
- rule.AccessDescriptorList.Insert(accessDescriptor);
- }
-
- ///////////////////////////////////////////////////////////////////////
- // fillRuleImpl - internal function
- //
- function fillRuleImpl( rule,
- strObjectID, strObject, eObjectType, bIsDllObject,
- strAppGroupID, strAppLabel, eAppAccountType,
- iAccessType1, iAccessResult1, iAuditLevel1,
- iAccessType2, iAccessResult2, iAuditLevel2,
- iAccessType3, iAccessResult3, iAuditLevel3,
- iAccessType4, iAccessResult4, iAuditLevel4,
- iAccessType5, iAccessResult5, iAuditLevel5,
- iAccessType6, iAccessResult6, iAuditLevel6,
- iAccessType7, iAccessResult7, iAuditLevel7,
- iAccessType8, iAccessResult8, iAuditLevel8,
- strRuleDescription, bHighPriority, bPreferred, bDisabled, bUseClientParser,
- strUsers, strDayTimeID, strDayTime, iOutConditionAND, iOutConditionOR, eOSVersion )
- {
- rule.ObjectType = parseInt(eObjectType);
- rule.PathType = strObjectID ? RT_DEFINITION : RT_DIRECT;
- rule.Path = strObjectID ? strObjectID : (strObject ? strObject : "");
- rule.DllObject = parseBoolean(bIsDllObject);
-
- rule.AccessDescriptorList.Clear();
-
- // fill the access type list
- if (iAccessType1 && parseInt(iAccessType1))
- WS_AddAccesDescriptorToRuleImpl( rule, iAccessType1, iAccessResult1, iAuditLevel1 );
- if (iAccessType2 && parseInt(iAccessType2))
- WS_AddAccesDescriptorToRuleImpl( rule, iAccessType2, iAccessResult2, iAuditLevel2 );
- if (iAccessType3 && parseInt(iAccessType3))
- WS_AddAccesDescriptorToRuleImpl( rule, iAccessType3, iAccessResult3, iAuditLevel3 );
- if (iAccessType4 && parseInt(iAccessType4))
- WS_AddAccesDescriptorToRuleImpl( rule, iAccessType4, iAccessResult4, iAuditLevel4 );
- if (iAccessType5 && parseInt(iAccessType5))
- WS_AddAccesDescriptorToRuleImpl( rule, iAccessType5, iAccessResult5, iAuditLevel5 );
- if (iAccessType6 && parseInt(iAccessType6))
- WS_AddAccesDescriptorToRuleImpl( rule, iAccessType6, iAccessResult6, iAuditLevel6 );
- if (iAccessType7 && parseInt(iAccessType7))
- WS_AddAccesDescriptorToRuleImpl( rule, iAccessType7, iAccessResult7, iAuditLevel7 );
- if (iAccessType8 && parseInt(iAccessType8))
- WS_AddAccesDescriptorToRuleImpl( rule, iAccessType8, iAccessResult8, iAuditLevel8 );
-
- rule.Application = strAppGroupID ? strAppGroupID : strAppLabel;
- rule.AppType = strAppGroupID ? AT_DEFINITION : AT_LABEL;
- rule.Priority = PRIOR_NORMAL;
- if (!parseBoolean(bUseClientParser))
- rule.Priority = parseBoolean(bHighPriority) ? PRIOR_HIGH : PRIOR_LOW;
- rule.Description = strRuleDescription ? strRuleDescription : "";
-
- //rule.Account = parseBoolean(bIsSystemAccount) ? RA_SYSTEM : RA_USER;
- rule.Account = eAppAccountType ? parseInt(eAppAccountType) : RA_USER;
-
- // rarely used fields
- rule.OutConditionAND = iOutConditionAND ? parseInt(iOutConditionAND) : 0;
- rule.OutConditionOR = iOutConditionOR ? parseInt(iOutConditionOR) : 0;
- // don't really know the TimeOfDay format....
- rule.TimeOfDayType = strDayTimeID ? RT_DEFINITION : RT_DIRECT;
- rule.TimeOfDay = strDayTimeID ? strDayTimeID : (strDayTime ? strDayTime : "");
- rule.Assignment = strUsers ? strUsers : "*";
- rule.Enabled = !(parseBoolean(bDisabled));
- rule.Preferred = parseBoolean(bPreferred);
- rule.OSVersion = eOSVersion ? parseInt(eOSVersion) : OSVER_WIN_ALL;
- }
-
- ///////////////////////////////////////////////////////////////////////
- // WS_UpdateRuleImpl
- // returns SUCCESS or error code
- //
- function WS_UpdateRuleImpl( strRuleID, strObjectID, strObject, eObjectType, bIsDllObject,
- strAppGroupID, strAppLabel, eAppAccountType,
- iAccessType1, iAccessResult1, iAuditLevel1,
- iAccessType2, iAccessResult2, iAuditLevel2,
- iAccessType3, iAccessResult3, iAuditLevel3,
- iAccessType4, iAccessResult4, iAuditLevel4,
- iAccessType5, iAccessResult5, iAuditLevel5,
- iAccessType6, iAccessResult6, iAuditLevel6,
- iAccessType7, iAccessResult7, iAuditLevel7,
- iAccessType8, iAccessResult8, iAuditLevel8,
- strRuleDescription, bHighPriority, bPreferred, bDisabled, bUseClientParser,
- strUsers, strDayTimeID, strDayTime, iOutConditionAND, iOutConditionOR, eOSVersion,
- bAvoidSavingSDB )
- {
- try {
- var ruleList = getRuleList( bUseClientParser );
- var rule = ruleList.Get(strRuleID);
- if (!rule)
- return ErrorHandler( ERR_EDIT_WS_RULE_FAILED, STR_EDIT_WS_RULE_FAILED );
-
- rule.AccessDescriptorList.Clear();
-
- fillRuleImpl( rule, strObjectID, strObject, eObjectType, bIsDllObject,
- strAppGroupID, strAppLabel, eAppAccountType,
- iAccessType1, iAccessResult1, iAuditLevel1,
- iAccessType2, iAccessResult2, iAuditLevel2,
- iAccessType3, iAccessResult3, iAuditLevel3,
- iAccessType4, iAccessResult4, iAuditLevel4,
- iAccessType5, iAccessResult5, iAuditLevel5,
- iAccessType6, iAccessResult6, iAuditLevel6,
- iAccessType7, iAccessResult7, iAuditLevel7,
- iAccessType8, iAccessResult8, iAuditLevel8,
- strRuleDescription, bHighPriority, bPreferred, bDisabled, bUseClientParser,
- strUsers, strDayTimeID, strDayTime, iOutConditionAND, iOutConditionOR, eOSVersion );
-
- saveWSChanges( bUseClientParser, bAvoidSavingSDB );
-
- return SUCCESS;
-
- } catch(e){
- return ErrorHandler( ERR_EDIT_WS_RULE_FAILED, STR_EDIT_WS_RULE_FAILED );
- }
- }
-
- ///////////////////////////////////////////////////////////////////////
- // WS_AddRuleImpl
- // returns strRuleID or "" on error
- //
- function WS_AddRuleImpl( strObjectID, strObject, eObjectType, bIsDllObject,
- strAppGroupID, strAppLabel, eAppAccountType,
- iAccessType1, iAccessResult1, iAuditLevel1,
- iAccessType2, iAccessResult2, iAuditLevel2,
- iAccessType3, iAccessResult3, iAuditLevel3,
- iAccessType4, iAccessResult4, iAuditLevel4,
- iAccessType5, iAccessResult5, iAuditLevel5,
- iAccessType6, iAccessResult6, iAuditLevel6,
- iAccessType7, iAccessResult7, iAuditLevel7,
- iAccessType8, iAccessResult8, iAuditLevel8,
- strRuleDescription, bHighPriority, bPreferred, bDisabled, bUseClientParser,
- strUsers, strDayTimeID, strDayTime, iOutConditionAND, iOutConditionOR, eOSVersion,
- bAvoidSavingSDB )
- {
- try {
- var ruleList = getRuleList( bUseClientParser );
- var newRule = ruleList.CreateRule();
-
- // generate the RuleID => must be unique and must maintain server/client syntax
- newRule.RuleID = ruleList.GenerateRuleID( parseInt(eObjectType), !parseBoolean(bUseClientParser));
- // newRule.RuleIDString is created automatically when newRule.RuleID is set
-
- fillRuleImpl( newRule, strObjectID, strObject, eObjectType, bIsDllObject,
- strAppGroupID, strAppLabel, eAppAccountType,
- iAccessType1, iAccessResult1, iAuditLevel1,
- iAccessType2, iAccessResult2, iAuditLevel2,
- iAccessType3, iAccessResult3, iAuditLevel3,
- iAccessType4, iAccessResult4, iAuditLevel4,
- iAccessType5, iAccessResult5, iAuditLevel5,
- iAccessType6, iAccessResult6, iAuditLevel6,
- iAccessType7, iAccessResult7, iAuditLevel7,
- iAccessType8, iAccessResult8, iAuditLevel8,
- strRuleDescription, bHighPriority, bPreferred, bDisabled, bUseClientParser,
- strUsers, strDayTimeID, strDayTime, iOutConditionAND, iOutConditionOR, eOSVersion );
-
- var strRuleID = newRule.RuleIDString;
-
- ruleList.Insert(newRule, newRule);
-
- saveWSChanges( bUseClientParser, bAvoidSavingSDB );
-
- return strRuleID;
-
- } catch(e){
- ErrorHandler( ERR_ADDING_WS_RULE_FAILED, STR_ADDING_WS_RULE_FAILED );
- return "";
- }
- }
-
- function WS_CopyRule( strSrcRuleID, bUseClientParser, bAvoidSavingSDB )
- {
- try {
- var ruleList = getRuleList( bUseClientParser );
- var rule = ruleList.CreateRule();
-
- var srcRule = ruleList.Get(strSrcRuleID);
-
- // generate the RuleID => must be unique and must maintain server/client syntax
- rule.RuleID = ruleList.GenerateRuleID( srcRule.ObjectType, !parseBoolean(bUseClientParser));
- // newRule.RuleIDString is created automatically when newRule.RuleID is set
-
- rule.ObjectType = srcRule.ObjectType;
- rule.PathType = srcRule.PathType;
- rule.Path = srcRule.Path;
- rule.DllObject = srcRule.DllObject;
-
- rule.Application = srcRule.Application;
- rule.AppType = srcRule.AppType;
- rule.Priority = srcRule.Priority;
- rule.Description = srcRule.Description;
-
- rule.Account = srcRule.Account;
-
- // rarely used fields
- rule.OutConditionAND = srcRule.OutConditionAND;
- rule.OutConditionOR = srcRule.OutConditionOR;
-
- // don't really know the TimeOfDay format....
- rule.TimeOfDayType = srcRule.TimeOfDayType;
- rule.TimeOfDay = srcRule.TimeOfDay;
- rule.Assignment = srcRule.Assignment;
- rule.Enabled = srcRule.Enabled;
- rule.Preferred = srcRule.Preferred;
- rule.OSVersion = srcRule.OSVersion;
-
- rule.AccessDescriptorList.Clear();
-
- //////////////////////////
- var accDescEnum = new Enumerator(srcRule.AccessDescriptorList);
- accDescEnum.moveFirst();
-
- while (!accDescEnum.atEnd())
- {
- var accDesc = accDescEnum.item();
-
- var accessDescriptor = rule.AccessDescriptorList.CreateAccessDescriptor();
-
- accessDescriptor.AccessType = accDesc.AccessType;
- accessDescriptor.AuditLevel = accDesc.AuditLevel;
- accessDescriptor.AccessResult = accDesc.AccessResult;
-
- rule.AccessDescriptorList.Insert(accessDescriptor);
-
- accDescEnum.moveNext();
- }
- ///////////////////////////
-
- var strRuleID = rule.RuleIDString;
-
- ruleList.Insert(rule, rule);
-
- saveWSChanges( bUseClientParser, bAvoidSavingSDB );
-
- return strRuleID;
-
- } catch(e){
- ErrorHandler( ERR_ADDING_WS_RULE_FAILED, STR_ADDING_WS_RULE_FAILED );
- return "";
- }
- }
-
- function WS_MoveRuleToServerDB( strSrcRuleID, bHighPriority )
- {
- try {
- var ruleList = getRuleList( true );
- var srcRule = ruleList.Get(strSrcRuleID);
-
- var ruleList = getRuleList( false );
- var rule = ruleList.CreateRule();
-
- // generate the RuleID => must be unique and must maintain server/client syntax
- rule.RuleID = ruleList.GenerateRuleID( srcRule.ObjectType, true);
- // newRule.RuleIDString is created automatically when newRule.RuleID is set
-
- rule.ObjectType = srcRule.ObjectType;
- rule.PathType = srcRule.PathType;
- rule.Path = srcRule.Path;
- rule.DllObject = srcRule.DllObject;
-
- rule.Application = srcRule.Application;
- rule.AppType = srcRule.AppType;
- rule.Priority = parseBoolean(bHighPriority) ? PRIOR_HIGH : PRIOR_LOW;
- rule.Description = srcRule.Description;
-
- rule.Account = srcRule.Account;
-
- // rarely used fields
- rule.OutConditionAND = srcRule.OutConditionAND;
- rule.OutConditionOR = srcRule.OutConditionOR;
-
- // don't really know the TimeOfDay format....
- rule.TimeOfDayType = srcRule.TimeOfDayType;
- rule.TimeOfDay = srcRule.TimeOfDay;
- rule.Assignment = srcRule.Assignment;
- rule.Enabled = srcRule.Enabled;
- rule.Preferred = srcRule.Preferred;
- rule.OSVersion = srcRule.OSVersion;
-
- rule.AccessDescriptorList.Clear();
-
- //////////////////////////
- var accDescEnum = new Enumerator(srcRule.AccessDescriptorList);
- accDescEnum.moveFirst();
-
- while (!accDescEnum.atEnd())
- {
- var accDesc = accDescEnum.item();
-
- var accessDescriptor = rule.AccessDescriptorList.CreateAccessDescriptor();
-
- accessDescriptor.AccessType = accDesc.AccessType;
- accessDescriptor.AuditLevel = accDesc.AuditLevel;
- accessDescriptor.AccessResult = accDesc.AccessResult;
-
- rule.AccessDescriptorList.Insert(accessDescriptor);
-
- accDescEnum.moveNext();
- }
- ///////////////////////////
-
- var strRuleID = rule.RuleIDString;
-
- ruleList.Insert(rule, rule);
-
- WS_DeleteRule( strSrcRuleID, true, false )
-
- saveWSChanges( true, false );
- saveWSChanges( false, false );
-
- return strRuleID;
-
- } catch(e){
- ErrorHandler( ERR_ADDING_WS_RULE_FAILED, STR_ADDING_WS_RULE_FAILED );
- return "";
- }
- }
-
- ///////////////////////////////////////////////////////////////////////
- // WS_DeleteRule
- function WS_DeleteRule( strRuleID, bUseClientParser, bAvoidSavingSDB )
- {
- try {
- var ruleList = getRuleList( bUseClientParser );
- var rule = ruleList.Get(strRuleID);
- if (rule)
- ruleList.Remove(rule);
-
- saveWSChanges( bUseClientParser, bAvoidSavingSDB );
- return SUCCESS;
- } catch(e){
- return ErrorHandler( ERR_DELETE_WS_RULE_FAILED, STR_DELETE_WS_RULE_FAILED );
- }
- }
-
- ///////////////////////////////////////////////////////////////////////
- // WS_EnableRule
- function WS_EnableRule( strRuleID, bDisable, bUseClientParser, bAvoidSavingSDB )
- {
- try {
-
- var ruleList = getRuleList( bUseClientParser );
-
- var rule = ruleList.Get(strRuleID);
- if (rule)
- rule.Enabled = parseBoolean(bDisable) ? false : true;
-
- saveWSChanges( bUseClientParser, bAvoidSavingSDB );
-
- return SUCCESS;
- } catch(e){
- return ErrorHandler( ERR_EDIT_WS_RULE_FAILED, STR_EDIT_WS_RULE_FAILED );
- }
- }
-
- ///////////////////////////////////////////////////////////////////////
- // WS_SetTime
- function WS_SetTime( strRuleID, strDayTime, strDayTimeID, bUseClientParser, bAvoidSavingSDB )
- {
- try {
-
- var ruleList = getRuleList( bUseClientParser );
-
- var rule = ruleList.Get(strRuleID);
- if (rule)
- {
- // don't really know the TimeOfDay format....
- rule.TimeOfDayType = strDayTimeID ? RT_DEFINITION : RT_DIRECT;
- rule.TimeOfDay = strDayTimeID ? strDayTimeID : (strDayTime ? strDayTime : "");
- }
-
- saveWSChanges( bUseClientParser, bAvoidSavingSDB );
- return SUCCESS;
- } catch(e){
- return ErrorHandler( ERR_EDIT_WS_RULE_FAILED, STR_EDIT_WS_RULE_FAILED );
- }
- }
-
- ///////////////////////////////////////////////////////////////////////
- // WS_SetUsers
- function WS_SetUsers( strRuleID, strUsers, bUseClientParser, bAvoidSavingSDB )
- {
- try {
-
- var ruleList = getRuleList( bUseClientParser );
-
- var rule = ruleList.Get(strRuleID);
- if (rule)
- {
- rule.Assignment = strUsers ? strUsers : "*";
- }
-
- saveWSChanges( bUseClientParser, bAvoidSavingSDB );
- return SUCCESS;
- } catch(e){
- return ErrorHandler( ERR_EDIT_WS_RULE_FAILED, STR_EDIT_WS_RULE_FAILED );
- }
- }
-
- ///////////////////////////////////////////////////////////////////////
- // WS_SetApp
- function WS_SetApp( strRuleID, strAppLabel, strAppGroupID, bUseClientParser, bAvoidSavingSDB )
- {
- try {
- var ruleList = getRuleList( bUseClientParser );
-
- var rule = ruleList.Get(strRuleID);
- if (rule)
- {
- rule.Application = strAppGroupID ? strAppGroupID : strAppLabel;
- rule.AppType = strAppGroupID ? AT_DEFINITION : AT_LABEL;
- }
-
- saveWSChanges( bUseClientParser, bAvoidSavingSDB );
- return SUCCESS;
- } catch(e){
- return ErrorHandler( ERR_EDIT_WS_RULE_FAILED, STR_EDIT_WS_RULE_FAILED );
- }
- }
-
- ///////////////////////////////////////////////////////////////////////
- // WS_SwitchRulePriority
- function WS_SwitchRulePriority( strRuleID, bAvoidSavingSDB )
- {
- try {
-
- var ruleList = getRuleList( false );
-
- var rule = ruleList.Get(strRuleID);
- if (rule)
- rule.Priority = (rule.Priority == PRIOR_LOW) ? PRIOR_HIGH : PRIOR_LOW;
-
- saveWSChanges( false, bAvoidSavingSDB );
- return SUCCESS;
- } catch(e){
- return ErrorHandler( ERR_EDIT_WS_RULE_FAILED, STR_EDIT_WS_RULE_FAILED );
- }
- }
-
-
- ///////////////////////////////////////////////////////////////////////
- // WS_SetRulePreferred
- function WS_SetRulePreferred( strRuleID, bPreferred, bAvoidSavingSDB )
- {
- try {
-
- var ruleList = getRuleList( false );
-
- var rule = ruleList.Get(strRuleID);
- if (rule)
- rule.Preferred = bPreferred;
-
- saveWSChanges( false, bAvoidSavingSDB );
- return SUCCESS;
- } catch(e){
- return ErrorHandler( ERR_EDIT_WS_RULE_FAILED, STR_EDIT_WS_RULE_FAILED );
- }
- }
-
-
- ///////////////////////////////////////////////////////////////////////
- // WS_SetRulePriority
- function WS_SetRulePriority( strRuleID, bHighPriority, bAvoidSavingSDB )
- {
- try {
-
- var ruleList = getRuleList( false );
-
- var rule = ruleList.Get(strRuleID);
- if (rule)
- rule.Priority = (bHighPriority) ? PRIOR_HIGH : PRIOR_LOW;
-
- saveWSChanges( false, bAvoidSavingSDB );
- return SUCCESS;
- } catch(e){
- return ErrorHandler( ERR_EDIT_WS_RULE_FAILED, STR_EDIT_WS_RULE_FAILED );
- }
- }
-
- ///////////////////////////////////////////////////////////////////////
- // WS_SetRuleAccount
- function WS_SetRuleAccount( strRuleID, eSystemAccountType, bAvoidSavingSDB )
- {
- try {
- var ruleList = getRuleList( false );
-
- var rule = ruleList.Get(strRuleID);
- if (rule)
- rule.Account = parseInt(eSystemAccountType);
-
- saveWSChanges( false, bAvoidSavingSDB );
- return SUCCESS;
- } catch(e){
- return ErrorHandler( ERR_EDIT_WS_RULE_FAILED, STR_EDIT_WS_RULE_FAILED );
- }
- }
-
- ///////////////////////////////////////////////////////////////////////
- // WS_SetObject
- function WS_SetObject(strRuleID, eObjectType, strObjectID, strObject, bIsDllObject, bUseClientParser, bAvoidSavingSDB)
- {
- try {
- var ruleList = getRuleList( bUseClientParser );
-
- var rule = ruleList.Get(strRuleID);
- if (rule)
- {
- rule.ObjectType = parseInt(eObjectType);
- rule.PathType = strObjectID ? RT_DEFINITION : RT_DIRECT;
- rule.Path = strObjectID ? strObjectID : (strObject ? strObject : "");
- rule.DllObject = parseBoolean(bIsDllObject);
- }
-
- saveWSChanges( bUseClientParser, bAvoidSavingSDB );
- return SUCCESS;
- } catch(e){
- return ErrorHandler( ERR_EDIT_WS_RULE_FAILED, STR_EDIT_WS_RULE_FAILED );
- }
- }
-
- ///////////////////////////////////////////////////////////////////////
- // getAllAccessTypes - internal function, used in WS_SetRuleAccess
- function getAllAccessTypes( eObjectType )
- {
- switch ( eObjectType )
- {
- case OT_FILE:
- return STR_FILE_ACCESS_TYPE_IDS.split("|");
- case OT_REGISTRY:
- return STR_REGISTRY_ACCESS_TYPE_IDS.split("|");
- case OT_SERVICE:
- return STR_SERVICE_ACCESS_TYPE_IDS.split("|");
- case OT_COMOBJECT:
- return STR_OLECOM_ACCESS_TYPE_IDS.split("|");
- case OT_SPAWNING:
- return STR_SPAWNING_ACCESS_TYPE_IDS.split("|");
- case OT_SPAWN_DLL:
- return STR_DLLLOAD_ACCESS_TYPE_IDS.split("|");
- case OT_SYSTEMPRIV:
- return STR_SYSPRIV_ACCESS_TYPE_IDS.split("|");
- case OT_DEVICE:
- return STR_DEVICE_ACCESS_TYPE_IDS.split("|");
- default:
- return 0;
- }
- }
-
- ///////////////////////////////////////////////////////////////////////
- // getFullAccessMask - internal function, used in WS_SetRuleAccess
- function getFullAccessMask( arrStrAT )
- {
- var iResult = 0;
-
- var i = 0;
- for (i = 0; i < arrStrAT.length; i++)
- iResult += parseInt(arrStrAT[i]);
-
- return iResult;
- }
-
- ///////////////////////////////////////////////////////////////////////
- // WS_SetRuleAccess
- function WS_SetRuleAccess( strRuleID, iAccessType, iAccessResult, iAuditLevel, bUseClientParser, bAvoidSavingSDB )
- {
- try {
- //alert( strRuleID + ", " + iAccessType + ", " + iAccessResult + ", " + iAuditLevel )
- //alert( iAccessType )
- //alert( iAccessResult )
- //alert( iAuditLevel )
- //alert( bUseClientParser )
- //alert( bAvoidSavingSDB )
-
- var ruleList = getRuleList( bUseClientParser );
- var rule = ruleList.Get(strRuleID);
- if (rule)
- {
- var arrStrAT = getAllAccessTypes( rule.ObjectType );
-
- var accDescEnum = new Enumerator(rule.AccessDescriptorList);
- accDescEnum.moveFirst();
-
- while (!accDescEnum.atEnd())
- {
- var accDesc = accDescEnum.item();
-
- // check, if access type is '*'
- if (arrStrAT && accDesc.AccessType == getFullAccessMask( arrStrAT ))
- { // if it is, then clear remove it from rule and create separate
- // AccessDescriptors for each individual access type
-
- var prevAR = accDesc.AccessResult;
- var prevAL = accDesc.AuditLevel;
-
- rule.AccessDescriptorList.Clear();
-
- var i = 0;
- for (i = 0; i < arrStrAT.length; i++)
- {
- if (parseInt(arrStrAT[i]) != iAccessType) // skip iAccessType this fnc is called for
- WS_AddAccesDescriptorToRuleImpl( rule, parseInt(arrStrAT[i]), prevAR, prevAL );
- }
-
- // finally add the access type this fnc is called for
- if (typeof(iAuditLevel) != "number")
- iAuditLevel = prevAL;
- if (typeof(iAccessResult) != "number")
- iAccessResult = prevAR;
-
- WS_AddAccesDescriptorToRuleImpl( rule, iAccessType, iAccessResult, iAuditLevel );
-
- saveWSChanges( bUseClientParser, bAvoidSavingSDB );
- return SUCCESS;
- }
-
- // check if this is the access type we want to change
- if (accDesc.AccessType == iAccessType)
- {
- if (typeof(iAccessResult) == "number")
- accDesc.AccessResult = iAccessResult ? parseInt(iAccessResult) : 0;
- if (typeof(iAuditLevel) == "number")
- accDesc.AuditLevel = iAuditLevel ? parseInt(iAuditLevel) : 0;
-
- saveWSChanges( bUseClientParser, bAvoidSavingSDB );
- return SUCCESS;
- }
- accDescEnum.moveNext();
- }
-
- if (typeof(iAuditLevel) != "number")
- iAuditLevel = AL_IGNORE;
-
- if (typeof(iAccessResult) != "number")
- iAccessResult = AR_ALLOW;
-
- WS_AddAccesDescriptorToRuleImpl( rule, iAccessType, iAccessResult, iAuditLevel );
- }
-
- saveWSChanges( bUseClientParser, bAvoidSavingSDB );
- return SUCCESS;
- } catch(e){
- //alert( "exception: " + e)
- return ErrorHandler( ERR_EDIT_WS_RULE_FAILED, STR_EDIT_WS_RULE_FAILED );
- }
- }
-
- ///////////////////////////////////////////////////////////////////////
- // WS_AddPredefinedObject
- function WS_AddPredefinedObject( strObjectID, eObjectType, strPath, bUseClientParser, bAvoidSavingSDB )
- {
- try {
- var definitionList = getDefinitionList( bUseClientParser );
- var definition = definitionList.CreateDefinition();
-
- definition.DefinitionID = strObjectID;
- definition.ObjectType = parseInt(eObjectType);
-
- if (strPath)
- {
- var newItem = definition.ItemList.CreateItem();
- newItem.Content = strPath;
- definition.ItemList.Insert(newItem);
- }
-
- definitionList.Insert( definition );
-
- saveWSChanges( bUseClientParser, bAvoidSavingSDB );
-
- return SUCCESS;
- }
- catch(e) {
- return ErrorHandler( ERR_ADDING_WS_OBJECT_FAILED, STR_ADDING_WS_OBJECT_FAILED );
- }
- }
-
- function WS_getDefinition( strObjectID, bUseClientParser )
- {
- var defList = getDefinitionList( bUseClientParser );
-
- try
- {
- return defList.Get( strObjectID );
- }
- catch (e)
- {
- return null;
- }
- }
-
- function WS_isObjNameUnique( strObjectID, bUseClientParser )
- {
- var defList = getDefinitionList( bUseClientParser );
-
- try
- {
- var definition = defList.Get( strObjectID );
- return false;
- }
- catch (e)
- {
- return true;
- }
- }
-
- ///////////////////////////////////////////////////////////////////////
- // WS_DeletePredefinedObject
- function WS_DeletePredefinedObject( strObjectID, bUseClientParser, bAvoidSavingSDB )
- {
- // remove it from WS database
- try {
- var definitionList = getDefinitionList( bUseClientParser );
-
- var definition = definitionList.Get( strObjectID );
- if (definition)
- definitionList.Remove(definition);
-
- saveWSChanges( bUseClientParser, bAvoidSavingSDB );
-
- return SUCCESS;
- }
- catch(e) {
- return ErrorHandler( ERR_DELETE_WS_OBJECT_FAILED, STR_DELETE_WS_OBJECT_FAILED );
- }
- }
-
- ///////////////////////////////////////////////////////////////////////
- // WS_AddPathToPredefinedObject
- function WS_AddPathToPredefinedObject( strObjectID, strPath, bUseClientParser, bAvoidSavingSDB )
- {
- try {
- var definitionList = getDefinitionList( bUseClientParser );
- var definition = definitionList.Get( strObjectID );
- var newItem = definition.ItemList.CreateItem();
- newItem.Content = strPath;
- definition.ItemList.Insert(newItem);
-
- saveWSChanges( bUseClientParser, bAvoidSavingSDB );
-
- return SUCCESS;
- }
- catch(e) {
- return ErrorHandler( ERR_EDIT_WS_OBJECT_FAILED, STR_EDIT_WS_OBJECT_FAILED );
- }
- }
-
- ///////////////////////////////////////////////////////////////////////
- // WS_RemovePathFromPredefinedObject
- function WS_RemovePathFromPredefinedObject( strObjectID, strPath, bUseClientParser, bAvoidSavingSDB )
- {
- try {
- var definitionList = getDefinitionList( bUseClientParser );
- var definition = definitionList.Get( strObjectID );
-
- var itemEnum = new Enumerator(definition.ItemList);
- itemEnum.moveFirst();
-
- while (!itemEnum.atEnd())
- {
- var item = itemEnum.item();
- if (item.Content == strPath)
- {
- definition.ItemList.Remove(item);
- break;
- }
- itemEnum.moveNext();
- }
-
- saveWSChanges( bUseClientParser, bAvoidSavingSDB );
-
- return SUCCESS;
- }
- catch(e) {
- return ErrorHandler( ERR_EDIT_WS_OBJECT_FAILED, STR_EDIT_WS_OBJECT_FAILED );
- }
- }
-
- ///////////////////////////////////////////////////////////////////////
- // WS_GetPredefinedObjectEnumerator
- function WS_GetPredefinedObjectEnumerator( strObjectID, bUseClientParser )
- {
- try {
- var definitionList = getDefinitionList( bUseClientParser );
- var definition = definitionList.Get( strObjectID );
-
- return new Enumerator(definition.ItemList);
- }
- catch(e) {
- return null;
- }
- }
-
- function WS_GetPredefinedObject( strObjectID, bUseClientParser )
- {
- try {
- var definitionList = getDefinitionList( bUseClientParser );
- var definition = definitionList.Get( strObjectID );
-
- return definition;
- }
- catch(e) {
- return null;
- }
- }
-
-
- ///////////////////////////////////////////////////////////////////////
- // WS_ClearAllPredefinedObjectContent
- function WS_ClearAllPredefinedObjectContent( strObjectID, bUseClientParser, bAvoidSavingSDB )
- {
- try {
- var definitionList = getDefinitionList( bUseClientParser );
- var definition = definitionList.Get( strObjectID );
-
- definition.ItemList.Clear();
-
- saveWSChanges( bUseClientParser, bAvoidSavingSDB );
-
- return SUCCESS;
- }
- catch(e) {
- return ErrorHandler( ERR_EDIT_WS_OBJECT_FAILED, STR_EDIT_WS_OBJECT_FAILED );
- }
- }
-
-
- ///////////////////////////////////////////////////////////////////////
- // WS_AddException
- function WS_AddException( iGuardsMask, strAppGroupID, strAppLabel, eAppAccountType, bHighPriority, strUsers, bAvoidSavingSDB )
- {
- try {
- var exceptionList = getAppExceptionList();
- var wsexception = exceptionList.CreateAppException();
-
- wsexception.AppType = strAppGroupID ? AT_DEFINITION : AT_LABEL;
- wsexception.Application = strAppGroupID ? strAppGroupID : strAppLabel;
- wsexception.ActiveGuards = parseInt(iGuardsMask);
- wsexception.Priority = parseBoolean(bHighPriority) ? PRIOR_HIGH : PRIOR_LOW;
- wsexception.Account = parseInt(eAppAccountType);
- wsexception.Assignment = strUsers ? strUsers : "*";
-
- exceptionList.Insert( wsexception );
-
- saveWSChanges( false, bAvoidSavingSDB );
-
- return SUCCESS;
- }
- catch(e) {
- return ErrorHandler( ERR_ADDING_WS_OBJECT_FAILED, STR_ADDING_WS_OBJECT_FAILED );
- }
- }
-
- ///////////////////////////////////////////////////////////////////////
- // WS_DeleteException
- function WS_DeleteException( strAppGroupID, strAppLabel, eAppAccountType, bHighPriority, strUsers, bAvoidSavingSDB )
- {
- // remove it from WS database
- try {
- var exceptionList = getAppExceptionList();
-
- var strApp = strAppGroupID ? strAppGroupID : strAppLabel;
- var Account = parseInt(eAppAccountType);
- var Priority = parseBoolean(bHighPriority) ? PRIOR_HIGH : PRIOR_LOW;
- if (!strUsers)
- strUsers = "*";
-
- var excListEnum = new Enumerator(exceptionList);
- excListEnum.moveFirst();
-
- while (!excListEnum.atEnd())
- {
- var wsexception = excListEnum.item();
- if (wsexception.Application == strApp && wsexception.Account == Account && wsexception.Priority == Priority && wsexception.Assignment == strUsers)
- {
- exceptionList.Remove(wsexception);
- break;
- }
- excListEnum.moveNext();
- }
-
- saveWSChanges( false, bAvoidSavingSDB );
-
- return SUCCESS;
- }
- catch(e) {
- return ErrorHandler( ERR_DELETE_WS_OBJECT_FAILED, STR_DELETE_WS_OBJECT_FAILED );
- }
- }
-
- ///////////////////////////////////////////////////////////////////////
- // WS_GetPropertyValue
- function WS_GetPropertyValue( strPropertyID )
- {
- try {
- var propList = getGlobalOptions();
- var prop = propList.Get( strPropertyID );
- return prop.Value;
- } catch(e) {
- return "";
- }
- }
-
- ///////////////////////////////////////////////////////////////////////
- // WS_SetPropertyValue
- function WS_SetPropertyValue( strPropertyID, Value, eType, bAvoidSavingSDB )
- {
- var propList = null;
- try {
- propList = getGlobalOptions();
- } catch(e) {
- return ErrorHandler( ERR_EDIT_SBX_PROPERTY_FAILED, STR_EDIT_SBX_PROPERTY_FAILED );
- }
-
- var prop = null;
- try {
- prop = propList.Get( strPropertyID );
- } catch(e) {
- }
-
- try {
-
- if (!prop)
- {
- prop = propList.CreateProperty();
- prop.Type = eType;
- prop.PropertyID = strPropertyID;
- propList.Insert(prop);
- }
- switch ( parseInt(eType) )
- {
- case PT_INT:
- prop.Value = parseInt(Value);
- break;
- case PT_BOOL:
- prop.Value = parseBoolean(Value);
- break;
- default:
- prop.Value = Value;
-
- }
-
- saveWSChanges( false, bAvoidSavingSDB );
- return SUCCESS;
- } catch(e) {
- return ErrorHandler( ERR_EDIT_SBX_PROPERTY_FAILED, STR_EDIT_SBX_PROPERTY_FAILED );
- }
- }
-
-